package model;


import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ini4j.Wini;

public class ConfigManager {

    private static Wini cfg;
    private static final String FILENAME = "C://Documents and Settings//Administrator.RRSSS//workspace//PaperAjaxTest//cfg//default.cfg";


    static {
        try {
//            String cfgFile = getCfgPath() + "default.cfg";
//            cfg = new Wini(new File(cfgFile));
            cfg = new Wini(new File(FILENAME));
        } catch (IOException ex) {
            Logger.getLogger(VMMachineFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private static String build;

    private static String getCfgPath() throws IOException{
        File pwd = new File(".");
        return pwd.getCanonicalPath()+"\\cfg\\";
    }


    public static String getBuildName() {
        return build;
    }

//    public static boolean reload() {
//        try {
//            cfg = new Wini(new File(getCfgPath()+"default.cfg"));
//            return true;
//        } catch (IOException ex) {
//            Logger.getLogger(VMMachineFactory.class.getName()).log(Level.SEVERE, null, ex);
//            return false;
//        }
//    }

    public static String getLogPath() {
        return cfg.get("server", "log_path");
    }

    public static String getScriptPath() {
        return cfg.get("server","script_path");
    }

    public static String getProjectPath() {
        return cfg.get("server","project_path");
    }

    public static String getServerHostName() {
        return cfg.get("server","hostname");
    }

    public static String getInstallerPath() {
        return cfg.get("server","installer_path");
    }

    public static String getVMMachineCfgFile() throws IOException{
//        return getCfgPath()+"machines.cfg";
        return "C://Documents and Settings//Administrator.RRSSS//workspace//PaperAjaxTest//cfg//machines.cfg";
    }

    public static String isStartedHandleName() {
        return cfg.get("handleName","is_vm_started");
    }

    public static String getSnapshotsHandleName() {
        return cfg.get("handleName","get_snapshots");
    }

    public static String revertToSnapshotHandleName() {
        return cfg.get("handleName","revert_vm");
    }

    public static void setBuildName(String buildName) {
        build = buildName;
    }

    public static String startVMHandleName() {
        return cfg.get("handleName","start_vm");
    }

    public static String runTSHandleName() {
        return cfg.get("handleName","run_script");
    }

    public static String getProjectArchiveName() {
        return cfg.get("server","project_archive_name");
    }

    public static String getZipHandleName() {
        return cfg.get("handleName","zip");
    }

    public static String getFSHandleName() {
        return cfg.get("handleName","copy_file");
    }

    public static String getUnzipHandleName() {
        return cfg.get("handleName","unzip");
    }

    public static String getTakeSnapshotHandleName() {
        return cfg.get("handleName","take_snapshot");
    }

    public static String getStopVMHandleName() {
        return cfg.get("handleName","stop_vm");
    }

    public static String getListHandlesHandleName(){
        return cfg.get("handleName", "list_handles");
    }

    public static void main(String[] args){
        try {
        	System.out.println(cfg.get("server","installer_path" ));
            File pwd = new File(".");
            System.out.println(pwd.getCanonicalPath());
            System.out.println(ConfigManager.getLogPath());
        } catch (IOException ex) {
            Logger.getLogger(ConfigManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
